package 银行;

import java.util.Scanner;

class BalanceException extends Exception{

    double balance;
    public BalanceException(double balance){

        super("余额不足！"+balance);

    }
}

public class Test {
    public static void main(String[] args)throws Exception{

        Account ac = new Account();
        boolean continueInput = true;
        do{
            try{
                System.out.println("Enter the money:");
                ac.withdraw(new Scanner(System.in).nextDouble());
                continueInput = false;
            }
            catch(BalanceException ex){
                System.out.println(ex.getMessage());
                System.out.println("Reset the money!");
            }
        }while (continueInput);
        System.out.println("Finish this action!");
    }
}

class Account{
    double balance = 5000;
    public void withdraw(double money)throws BalanceException{
        if(money > this.balance){
            throw new BalanceException(balance);
        }
        else balance-=money;
    }
}
